package com.mskj.zxmy.common;

import com.mskj.zxmy.dto.CKDanSaveDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serializable;

@Schema(description = "统一响应结果")
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(description = "响应状态码", example = "200")
    private int code;        // 状态码
    
    @Schema(description = "响应消息", example = "操作成功")
    private String message;  // 消息
    
    @Schema(description = "响应数据")
    private T data;     // 数据

    public Result() {}

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(int i, String 操作成功, Object o) {

    }

    // 成功响应（无数据）
    public static <T> Result<T> success(String message) {
        return new Result<>(ResultCode.SUCCESS.getCode(), message);
    }

    public static <T> Result<T> data(T data) {
        Result<T> res = new Result<>();
        res.setCode(200);
        res.setData(data);
        res.setMessage("success");
        return res;
    }


    // 成功响应（带数据）
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }
    public static Result success() {
        return new Result(0, "操作成功", null);
    }

    // 失败响应
    public static <T> Result<T> failed(String message) {
        return new Result<>(ResultCode.FAILED.getCode(), message);
    }

    // 自定义响应
    public static <T> Result<T> of(int code, String message, T data) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message);
    }
//    // 链式调用设置数据
//    public Result<CKDanSaveDTO> data(T data) {
//        this.setData(data);
//        return this;
//    }

    // 链式调用设置消息
    public Result<T> message(String message) {
        this.setMessage(message);
        return this;
    }


    // Getters and Setters
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
